package com.allianz.webapps.secondController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.allianz.webapps.common.CustomerContextHolder;
import com.allianz.webapps.https.interfaces.type001.pojo.User;
import com.allianz.webapps.service.OcpPolicyContractsService;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;


@RequestMapping(value="/ocp")
@Controller
public class OcpPolicyController {
	
	@Autowired
	OcpPolicyContractsService  ocpService;
	@Autowired
	ObjectMapper  obMapper;
	
	/**
	 * 查询用户续期列表
	 * @param request
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/getOcpDetailList")
	@ResponseBody
	public List<Map<String, Object>>  getDetailList(HttpServletRequest request,HttpSession session)throws Exception{
			CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_ALLIANZ);
			User user = (User) session.getAttribute("username");
			List<Map<String, Object>> ocps=ocpService.queryOcpList(Long.parseLong(user.getAgentId()));
			return ocps;
	}
	/**
	 * 查询用户续期列表详情
	 * @param jsonParam
	 * @return
	 * @throws JsonParseException
	 * @throws JsonMappingException
	 * @throws IOException
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/getOcpListDetail")
	@ResponseBody
	public Map<String, Object> getListDetail(@RequestParam(value="jsonParam")String jsonParam) throws JsonParseException, JsonMappingException, IOException{
		Map<String,Object> map = obMapper.readValue(jsonParam, Map.class);
		String fromDa = (String) map.get("fromDate");
		String contract = (String)map.get("contractId");
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_ALLIANZ);
		return ocpService.queryOcpListDetail(fromDa, Long.parseLong(contract));
	}
}
